home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 June / june_2001.iso / Html / CuteHtml / setup.exe / +TELLS A VISITOR HOW MANY TIMES THEY HAVE BEEN TO YOUR SITE.JS < prev    next >
Encoding:
Text File  |  1999-09-03  |  2.9 KB  |  95 lines

  1. <SCRIPT LANGUAGE="JavaScript">
  2.  
  3. <!-- This script will show someone how many times that they have visited your website. It
  4. also has a few humorous messages that you can give them when they arrive. 
  5.  
  6. function getCookieVal (offset) {
  7. var endstr = document.cookie.indexOf (";", offset);
  8. if (endstr == -1)
  9. endstr = document.cookie.length;
  10. return unescape(document.cookie.substring(offset, endstr));
  11. }
  12. function GetCookie (name) {
  13. var arg = name + "=";
  14. var alen = arg.length;
  15. var clen = document.cookie.length;
  16. var i = 0;
  17. while (i < clen) {
  18. var j = i + alen;
  19. if (document.cookie.substring(i, j) == arg)
  20. return getCookieVal (j);
  21. i = document.cookie.indexOf(" ", i) + 1;
  22. if (i == 0) 
  23. break; 
  24. }
  25. return null;
  26. }
  27. function SetCookie (name, value) {
  28. var argv = SetCookie.arguments;
  29. var argc = SetCookie.arguments.length;
  30. var expires = (2 < argc) ? argv[2] : null;
  31. var path = (3 < argc) ? argv[3] : null;
  32. var domain = (4 < argc) ? argv[4] : null;
  33. var secure = (5 < argc) ? argv[5] : false;
  34. document.cookie = name + "=" + escape (value) +
  35. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  36. ((path == null) ? "" : ("; path=" + path)) +
  37. ((domain == null) ? "" : ("; domain=" + domain)) +
  38. ((secure == true) ? "; secure" : "");
  39. }
  40. function DisplayInfo() {
  41. var expdate = new Date();
  42. var visit;
  43. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  44. if(!(visit = GetCookie("visit"))) 
  45. visit = 0;
  46. visit++;
  47. SetCookie("visit", visit, expdate, "/", null, false);
  48. var message;
  49. if(visit == 1) 
  50. message="         Welcome to my page!";
  51. if(visit== 2) 
  52. message="           I see you came back !";
  53. if(visit == 3) 
  54. message="               Oh, it's you again!";
  55. if(visit == 4)
  56. message="            You must be curious!"; 
  57. if(visit == 5) 
  58. message="      You're practically a regular!";
  59. if(visit == 6) 
  60. message="              You need a hobby!";
  61. if(visit == 7)
  62. message="             Nothing better to do?"; 
  63. if(visit == 8) 
  64. message="            Don't you ever sleep?";
  65. if(visit == 9)
  66. message="                      Get a life!!!"; 
  67. if(visit >= 10) 
  68. message="  Rent is due on the 1st of the month!";
  69.   alert("\n"+"Your browser has visited this page               \n"
  70.             +"                              "+visit+"\n"
  71.             +"                          time(s)."+"\n"+"\n"
  72.             +message);
  73. }
  74. function ResetCounts() {
  75. var expdate = new Date();
  76. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  77. visit = 0;
  78. SetCookie("visit", visit, expdate , "/", null, false);
  79. history.go(0);
  80. }
  81.  
  82. window.onload=DisplayInfo
  83.  
  84. -->
  85.  
  86. </Script>
  87.  
  88. <!-- Supporting buttons that will let the viewer reload the page or reset the counter -->
  89.  
  90. <FORM>
  91. <CENTER>
  92. <INPUT NAME="update" TYPE="BUTTON" VALUE="Revisit  Page" OnClick="history.go(0)">
  93. <INPUT NAME="reset" TYPE="BUTTON" VALUE="Reset Counter" OnClick="ResetCounts()">
  94. </CENTER>
  95. </FORM>